package com.no1.dao;

import com.no1.entity.Worker;
import com.no1.utils.DBHelper;
import com.no1.utils.MD5Helper;
import com.sun.javafx.collections.MappingChange;
import org.junit.Test;

import java.util.*;

public class WorkerDao {
    //职工登录、
    public boolean login(String username, String password) {
        String sql = "select * from  worker where wid = ? and mima = ?";
        List<String> params = new ArrayList<>();
        params.add(username);
        params.add(MD5Helper.getMd5(password));
        return DBHelper.executeQuery(sql, params).size() > 0;
    }
    //获取职工信息
    public Worker getWorker(String  wid){
        String sql = "select * from worker where wid=?";
        List<String> params = new ArrayList<>();
        params.add(wid);
        List<Map<String,Object>> values = DBHelper.executeQuery(sql,params);
        if(values.size()==0){
            return null;
        }
        Worker worker = new Worker();
        Map<String,Object> va = values.get(0);
        worker.setWid((String) va.get("wid"));
        worker.setRid((Integer) va.get("rid"));
        worker.setWname((String) va.get("wname"));
        worker.setLandscape((String) va.get("landscape"));
        worker.setAddress((String) va.get("address"));
        worker.setDepid(Integer.parseInt(va.get("deptid").toString()));
        worker.setWhometown((String) va.get("whometown"));
        worker.setWpal((Double) va.get("wpay"));
        worker.setWtel((String) va.get("wtel"));
        worker.setWtitle((String) va.get("wtitle"));
        worker.setWxueli((String) va.get("xueli"));
        return worker;
    }
    @Test
    public void test(){
        getWorker("admin");
    }
}
